package com.link.base.base.product.service;

import com.link.base.base.image.dao.mybatis.mapper.AppImageMapper;
import com.link.base.base.image.model.Image;
import com.link.base.base.product.dao.mybatis.mapper.GuideProdCaseMapper;
import com.link.base.base.product.model.GuideProdCase;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.dao.siebel.mapper.BasicMapperSiebel;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author XYQ
 * @date 2017/10/13
 * @comments 案例与产品操作
 */
@Service
public class GuideProdCaseServiceImpl extends BasicServiceImpl<GuideProdCase> implements GuideProdCaseService {

    @Resource
    private GuideProdCaseMapper guideProdCaseMapper;
    @Resource
    private AppImageMapper appImageMapper;

    @Override
    public BasicMapper<GuideProdCase> getBasicMapper() {
        return guideProdCaseMapper;
    }

    @Override
    public BasicMapperSiebel<GuideProdCase> getSiebelBasicMapper() throws Exception {

        return null;
    }

    /**
     * 根据案例id查询与之相关联的产品集合
     *
     * @author XYQ
     * 2017年10月13日
     */
    @Override
    public List<GuideProdCase> queryByCaseBaseId(GuideProdCase record) throws Exception {
        return guideProdCaseMapper.queryByCaseBaseId(record);
    }

    /**
     * 根据产品id查询与之相关联的案例集合
     *
     * @author XYQ
     * 2017年10月16日
     */
    @Override
    public List<GuideProdCase> queryByProductId(GuideProdCase record) throws Exception {
        List<GuideProdCase> list = guideProdCaseMapper.queryByProductId(record);
        Image image = new Image();
        for (int i = 0; i < list.size(); i++) {
            image.setParentid(list.get(i).getId());
            image.setModule("CaseBase");
            List<Image> imageList = appImageMapper.queryAll(image);
            list.get(i).setImageList(imageList);
        }
        return list;
    }
}
